/*
 * BanBu_DynamicController
 * @description 本文件提供来访记录界面的ViewController
 * @package
 * @author 		***
 * @copyright
 * @version 		1.0
 * @description 本文件提供来访记录界面的ViewController
 */

#import "BanBu_DynamicController.h"
#import "BanBu_GridCell.h"
#import "BanBu_PersonDataViewController.h"
#import "AppDataManager.h"
#import "AppCommunicationManager.h"
#import "TKLoadingView.h"
#import "UIBadgeView.h"
#import "BanBu_NavButton.h"
#import "BanBu_ImageView.h"
#import "BanBu_ThemeManager.h"
#import "LeveyTabBarController.h"
BOOL firstIn = NO;
@interface BanBu_DynamicController ()

-(NSString *)BindUserid:(NSString *)usrid;

@end

@implementation BanBu_DynamicController
@synthesize dataArr = _dataArr,type = _type,number=_number;


-(void)dealloc{
//    [_dataArr release];
    [super dealloc];
}

-(id)initWithDynamicDisplayType:(ADisplayType)type{
    self = [super initWithStyle:UITableViewStylePlain];
    if(self){
        _type = type;
    }
    return self;
}

// 建立个数
-(void)setNumber:(NSString *)number
{

  UIBadgeView *badgeView = (UIBadgeView *)[self.view viewWithTag:1414];
   if(!number||![number intValue])
    {
        if(badgeView)
            [badgeView removeFromSuperview];
    }
    else
    {
        float width = [number sizeWithFont:[UIFont boldSystemFontOfSize:14]].width+12;
        if(!badgeView)
        {
            badgeView = [[UIBadgeView alloc] initWithFrame:CGRectMake(self.navigationItem.rightBarButtonItem.customView.bounds.size.width-width, -2, width, 20)];
            badgeView.tag = 1414;
            badgeView.backgroundColor = [UIColor clearColor];
            badgeView.badgeColor = [UIColor redColor];
            [self.navigationItem.rightBarButtonItem.customView addSubview:badgeView];
//            [badgeView release];
        }
        badgeView.badgeString = number;
        [UIView animateWithDuration:0.5
                         animations:^{
                             badgeView.frame = CGRectMake(self.navigationItem.rightBarButtonItem.customView.bounds.size.width-width, -2, width, 20);
                             
                         }];
    }

	}
-(void)popself
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    firstIn = YES;
    BanBu_ImageView *img = [[[BanBu_ImageView alloc] initWithBackGroundImageType:UIImageViewCreatTypeTable] autorelease];
    self.tableView.backgroundView = img;
        
    self.title = NSLocalizedString(@"visitorLabel", nil);
    self.view.backgroundColor = [UIColor colorWithRed:255.0/255 green:250.0/255 blue:240.0/255 alpha:1.0];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    
    if(![[UserDefaults valueForKey:[self BindUserid:MyAppDataManager.useruid]] boolValue]&&[MyAppDataManager.friendViewList count]>0)
    {
        NSString *numberString = [[NSString alloc]initWithFormat:@"%i",[MyAppDataManager.friendViewList count]];
        self.number=numberString;
        [numberString release];
    }
    
    if (self.fromDialog)
    {
        [self.leveyTabBarController hidesTabBar:NO animated:YES];
        
        segmentController = [[AKSegmentedControl alloc] initWithFrame:CGRectMake(5,5,196,34)];
        [segmentController setDelegate:self];
        [self setupSegmentedControl];
        
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeTheme) name:kThemeDidChangeNotification object:nil];
        [self createClearButton];
//        self.navigationItem.leftBarButtonItem = nil;
    }
}

-(void)createClearButton
{
    //添加“清除标记”按钮
    BanBu_NavButton *clearButton = [[BanBu_NavButton alloc] initWithButtonType:UIButtonCreatTypeNormal];
    clearButton.position = ButtonPositionLeft;
    clearButton.hidden = YES;
    [clearButton setImage:[UIImage imageNamed:@"DialogClearButton.png"] forState:UIControlStateNormal];
    clearButton.frame=CGRectMake(0, 0,40, 30);
    
    UIBarButtonItem *clearItem = [[[UIBarButtonItem alloc] initWithCustomView:clearButton] autorelease];
    self.navigationItem.leftBarButtonItem = clearItem;
}

-(NSString *)BindUserid:(NSString *)usrid
{
    return [@"myusridis"stringByAppendingString:usrid];
}



- (void)record:(UIButton *)button
{
    [UserDefaults setValue:@"1" forKey:[self BindUserid:MyAppDataManager.useruid]];
    
    //去掉 uibadageview
    for(UIView *s in self.navigationItem.rightBarButtonItem.customView.subviews )
    {
        if([s isKindOfClass:[UIBadgeView class]])
            [s removeFromSuperview];
    }
    
    if([self.view viewWithTag:100])
    {
        [[self.view viewWithTag:100]removeFromSuperview];
        [[self.view viewWithTag:101]removeFromSuperview];
    }
    
    self.title = _type == DisplayFriendsNews?NSLocalizedString(@"displayVisitRecord", nil):NSLocalizedString(@"displayFriendNews", nil);
    if(self.type == DisplayVisitRecord)
    {
        self.type = DisplayFriendsNews;
        [button setTitle:NSLocalizedString(@"displayVisitRecord", nil) forState:UIControlStateNormal];
       // CGFloat btnLen = [NSLocalizedString(@"displayVisitRecord", nil) sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(100, 30)].width;
      //  button.frame = CGRectMake(button.frame.origin.x, button.frame.origin.y, btnLen+20, 30);
        button.frame=CGRectMake(0, 0,70, 30);
        
        if(!MyAppDataManager.friendsDos.count)
        {
            [self setRefreshing];
            return;
        }
    }
    else
    {
        self.type = DisplayVisitRecord;
        [button setTitle:NSLocalizedString(@"displayFriendNews", nil) forState:UIControlStateNormal];
       // CGFloat btnLen = [NSLocalizedString(@"displayFriendNews", nil) sizeWithFont:[UIFont systemFontOfSize:14] constrainedToSize:CGSizeMake(100, 30)].width;
      //  button.frame = CGRectMake(button.frame.origin.x, button.frame.origin.y, btnLen+20, 30);
        if(![MyAppDataManager.friendViewList count])
        {
            if(cryImageView || noticeLabel)
            {
                [[self.view viewWithTag:100]removeFromSuperview];
                [[self.view viewWithTag:101]removeFromSuperview];
            }
            cryImageView = [[UIImageView alloc]initWithFrame:CGRectMake(136, 100, 48, 48)];
            cryImageView.tag = 100;
            cryImageView.image = [UIImage imageNamed:@"cry.png"];
            [self.tableView addSubview:cryImageView];
//            [cryImageView release];
            noticeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 150, 300, 100)];
            noticeLabel.tag = 101;
            noticeLabel.numberOfLines = 0;
            noticeLabel.text = NSLocalizedString(@"visitRecordNoticeLabel", nil);
            noticeLabel.font = [UIFont systemFontOfSize:16];
            noticeLabel.textAlignment = kTextAlignmentCenter;
            noticeLabel.textColor = [UIColor darkGrayColor];
            noticeLabel.backgroundColor = [UIColor clearColor];
            [self.tableView addSubview:noticeLabel];
//            [noticeLabel release];
        }
        
        if(!MyAppDataManager.friendViewList.count)
        {
            [self setRefreshing];
            return;
        }
        if([self.view viewWithTag:100])
        {
            [[self.view viewWithTag:100] removeFromSuperview];
            [[self.view viewWithTag:101] removeFromSuperview];
        }
    }
//    [UIView beginAnimations:@"change" context:nil];
//    [UIView setAnimationDuration:0.5];
//    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];
//    [UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:self.tableView cache:YES];
//    [self.tableView reloadData];
//    [UIView commitAnimations];
    CATransition *animation = [CATransition animation];
    animation.duration = 0.8;
    animation.timingFunction = UIViewAnimationCurveEaseInOut;
    animation.type = @"rippleEffect";
    [self.tableView reloadData];
    [self.view.layer addAnimation:animation forKey:@"animation"];
}

-(void)setType:(ADisplayType)type
{
    if(_type == type)
    {
        return;
    }
    _type = type;
    [self.tableView reloadData];
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
//    self.dataArr=nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

-(void)viewDidAppear:(BOOL)animated
{
    //设置没有新的来访记录，对话界面不再显示红点
    MyAppDataManager.newRecord = NO;
    if (self.fromDialog)
    {
        [self.leveyTabBarController hidesTabBar:NO animated:YES];
    }
    
    if(!MyAppDataManager.friendViewList.count||firstIn)
    {
        [self setRefreshing];
        return;
    }
    
}

#pragma mark - 请求数据

-(void)loadingData
{
    firstIn = NO;
    if([self.view viewWithTag:100])
    {
        [[self.view viewWithTag:100]removeFromSuperview];
        [[self.view viewWithTag:101]removeFromSuperview];
    }
    NSMutableDictionary *parDic = [NSMutableDictionary dictionary];
    [parDic setValue:[NSString stringWithFormat:@"%.f",AppLocationManager.curLocation.latitude*1000000] forKey:Latitude];
    [parDic setValue:[NSString stringWithFormat:@"%.f",AppLocationManager.curLocation.longitude*1000000] forKey:Longitude];
    [parDic setValue:[MyAppDataManager getLanguageSubmitToServer] forKey:@"lang"];
    [AppComManager getBanBuData:BanBu_Get_Friend_ViewList par:parDic delegate:self];
}

-(void)viewWillAppear:(BOOL)animated
{
   // 这是一进视图就要开始请求最近的来访记录
    [super viewWillAppear:animated];
    [AppComManager cancalHandlesForObject:self];
}


-(void)viewWillDisappear:(BOOL)animated
{
    [super viewWillDisappear:animated];
    
    [AppComManager cancalHandlesForObject:self];
}


#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    if(_type ==DisplayFriendsNews)
    {
        return MyAppDataManager.friendsDos.count;
    }
    else
    {
        if([MyAppDataManager.friendViewList count]%4!=0)
        {
            gridViewRow = [MyAppDataManager.friendViewList count]/4+1;
        }
        else
        {
            gridViewRow = [MyAppDataManager.friendViewList count]/4;
        }
        return gridViewRow;
    }
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(_type == DisplayFriendsNews)
    {
        return 85;
    }
    else
    {
        return 79;
    }
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *VisitCellIdentifier=@"ViewCellIdentifier";
    BanBu_GridCell *cell = (BanBu_GridCell *)[tableView dequeueReusableCellWithIdentifier:VisitCellIdentifier];
    if(cell == nil)
    {
        cell = [[[BanBu_GridCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:VisitCellIdentifier] autorelease];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
        cell.delegate = self;
        cell.backgroundColor = [UIColor clearColor];
    }
    if(cell.contentView.subviews.count)
    {
        for(UIButton *temp in cell.contentView.subviews)
        {
            temp.hidden = YES;
        }
    }
    if(gridViewRow-1 == indexPath.row && MyAppDataManager.friendViewList.count%4 != 0)
    {
        for (int i=0; i<MyAppDataManager.friendViewList.count%4; i++)
        {
            NSDictionary *personDic=[[MyAppDataManager.friendViewList objectAtIndex:i+indexPath.row*4] valueForKey:@"userinfor"];
            [cell setImage:[personDic valueForKey:@"uface"] distance:[MyAppDataManager IsInternationalLanguage:[personDic valueForKey:@"dmeter"]] sex:[personDic valueForKey:@"gender"] flag:NO forTile:i name:[personDic valueForKey:@"pname"] vip:[[personDic valueForKey:@"userlevel"] integerValue]>0 verify:[[personDic valueForKey:@"verify"] boolValue]];
        }
    }
    else
    {
        for (int i=0; i<4; i++)
        {
            NSDictionary *personDic=[[MyAppDataManager.friendViewList objectAtIndex:i+indexPath.row*4] valueForKey:@"userinfor"];
            [cell setImage:[personDic valueForKey:@"uface"] distance:[MyAppDataManager IsInternationalLanguage:[personDic valueForKey:@"dmeter"]] sex:[personDic valueForKey:@"gender"] flag:NO forTile:i name:[personDic valueForKey:@"pname"] vip:[[personDic valueForKey:@"userlevel"] integerValue]>0 verify:[[personDic valueForKey:@"verify"] boolValue]];
        }
    }
    return  cell;
}

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}

- (BOOL)tableView:(UITableView *)tableView shouldIndentWhileEditingRowAtIndexPath:(NSIndexPath *)indexPath
{
    return YES;
}



#pragma mark - gridDelegate

-(void)gridCell:(BanBu_GridCell *)cell didSelectedTile:(NSInteger)tileIndex realRow:(NSInteger)row{
//    NSLog(@"%d----%d",row,MyAppDataManager.friendViewList.count);
    if(row<[MyAppDataManager.friendViewList count]){
        
//        NSDictionary *buddy = [MyAppDataManager.friendViewList objectAtIndex:row];
//        BanBu_PersonDataViewController *peopleFfofile = [[BanBu_PersonDataViewController alloc] initWithProfile:buddy];
//        [self.navigationController pushViewController:peopleFfofile animated:YES];
//        [peopleFfofile release];
        
        
        
        NSDictionary *buddy = [MyAppDataManager.friendViewList objectAtIndex:row];
        BanBu_PersonDataViewController *peopleFfofile = [[BanBu_PersonDataViewController alloc] initWithProfile:[buddy valueForKey:keyPersonalInfo]];
        [self.navigationController pushViewController:peopleFfofile animated:YES];
        [peopleFfofile release];
        
    }
}

#pragma mark - BanBuDelegate

- (void)banbuRequestDidFinished:(NSDictionary *)resDic error:(NSError *)error
{
    self.navigationController.view.userInteractionEnabled = YES;
    [TKLoadingView dismissTkFromView:self.view animated:YES afterShow:0.0];
    if(error)
    {
        if([error.domain isEqualToString:BanBuDataformatError])
        {
            [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:2.0];
        }
        else
        {
            [TKLoadingView showTkloadingAddedTo:self.view title:NSLocalizedString(@"network_error", nil) activityAnimated:NO duration:2.0];
        }
        
        [self finishedLoading];
        return;
    }
    
    if([AppComManager respondsDic:resDic isFunctionData:BanBu_Get_Friend_ViewList])
    {
        if([[resDic valueForKey:@"ok"]boolValue]){
            if(_isLoadingRefresh)
            {
                
                [MyAppDataManager.friendViewList removeAllObjects];
            }
            
            NSString *flistString = [NSString stringWithFormat:@",%@,%@,",[[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"friendlist"] valueForKey:@"x"],[[[UserDefaults valueForKey:MyAppDataManager.useruid] valueForKey:@"friendlist"] valueForKey:@"z"]];
            NSMutableArray *userList = [NSMutableArray arrayWithArray:[resDic valueForKey:@"list"]];
            for(int i=0;i<[userList count];i++)
            {
                NSDictionary *dic =      [userList objectAtIndex:i];
                NSLog(@"%@",dic);
                NSString     *idString = [dic valueForKey:@"userid"];
                if([flistString rangeOfString:idString].location != NSNotFound&&flistString.length)
                {
                    [userList removeObjectAtIndex:i];
                }
            }
            
            [MyAppDataManager.friendViewList addObjectsFromArray:userList];
            if(![MyAppDataManager.friendViewList count]){
                if(cryImageView || noticeLabel){
                    [[self.view viewWithTag:100]removeFromSuperview];
                    [[self.view viewWithTag:101]removeFromSuperview];
                }
                cryImageView = [[UIImageView alloc]initWithFrame:CGRectMake(136, 100, 48, 48)];
                cryImageView.tag = 100;
                cryImageView.image = [UIImage imageNamed:@"cry.png"];
                [self.tableView addSubview:cryImageView];
                noticeLabel = [[UILabel alloc]initWithFrame:CGRectMake(10, 150, 300, 100)];
                noticeLabel.tag = 101;
                noticeLabel.numberOfLines = 0;
                noticeLabel.text = NSLocalizedString(@"visitRecordNoticeLabel", nil);
                noticeLabel.font = [UIFont systemFontOfSize:16];
                noticeLabel.textAlignment = kTextAlignmentCenter;
                noticeLabel.textColor = [UIColor darkGrayColor];
                noticeLabel.backgroundColor = [UIColor clearColor];
                [self.tableView addSubview:noticeLabel];
            }
            else
            {
                __block  NSArray *saveArray = [[NSArray alloc] initWithArray:[resDic valueForKey:@"list"]];
                dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
                dispatch_async(queue, ^{
                    [MyAppDataManager writePersonalDataToDB:saveArray];
                    [saveArray release];
                });
            }
        }
    }
    [self.tableView reloadData];
    [self finishedLoading];
}


-(void)changeTheme
{
    UIImage *backgroundImage = [ThemeManager getThemeImage:@"segmentTitle.png"];//[[ThemeManager getThemeImage:@"segmentTitle.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];
    
    [segmentController setBackgroundImage:backgroundImage];
//    if(segmentController)
//    {
//        [segmentController release];
//    }
//    segmentController = [[AKSegmentedControl alloc] initWithFrame:CGRectMake(5,5,196,34)];
//    [segmentController setDelegate:self];
//    [self setupSegmentedControl];
}

- (void)setupSegmentedControl
{
    NSArray *titleArr = [NSArray arrayWithObjects:NSLocalizedString(@"dialogueTitle", nil),NSLocalizedString(@"visitorLabel", nil), nil];
    UIImage *backgroundImage = [ThemeManager getThemeImage:@"segmentTitle.png"];//[[ThemeManager getThemeImage:@"segmentTitle.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(10.0, 10.0, 10.0, 10.0)];
    
    [segmentController setBackgroundImage:backgroundImage];
    [segmentController setAutoresizingMask:UIViewAutoresizingFlexibleRightMargin|UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleBottomMargin];
    
    UIImage *buttonBackgroundImagePressed_left = [UIImage imageNamed:@"segmented-bg-pressed_left.png"];
    UIImage *buttonBackgroundImagePressed_right = [UIImage imageNamed:@"segmented-bg-pressed_right.png"];
    
    //对话Button
    UIButton *buttonTalk = [[[UIButton alloc] init] autorelease];
    [buttonTalk setTitle:[titleArr objectAtIndex:0] forState:UIControlStateNormal];
    [buttonTalk setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buttonTalk.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0]];
    
    [buttonTalk setBackgroundImage:buttonBackgroundImagePressed_left forState:UIControlStateHighlighted];
    [buttonTalk setBackgroundImage:buttonBackgroundImagePressed_left forState:UIControlStateSelected];
    [buttonTalk setBackgroundImage:buttonBackgroundImagePressed_left forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
    UIImageView *lineview1 = [[UIImageView alloc] initWithFrame:CGRectMake(segmentController.frame.size.width/2, 0, 1, segmentController.frame.size.height)];
//    lineview1.image = [UIImage imageNamed:@"segmented-separator.png"];
    [buttonTalk addSubview:lineview1];
    [lineview1 release];
    
    // 来访记录Button
    UIButton *buttonVisit = [[[UIButton alloc] init] autorelease];
    
    [buttonVisit setTitle:[titleArr objectAtIndex:1] forState:UIControlStateNormal];
    [buttonVisit setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [buttonVisit.titleLabel setFont:[UIFont fontWithName:@"HelveticaNeue-Bold" size:15.0]];
    [buttonVisit setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 5.0, 0.0, 0.0)];
    
    [buttonVisit setBackgroundImage:buttonBackgroundImagePressed_right forState:UIControlStateHighlighted];
    [buttonVisit setBackgroundImage:buttonBackgroundImagePressed_right forState:UIControlStateSelected];
    [buttonVisit setBackgroundImage:buttonBackgroundImagePressed_right forState:(UIControlStateHighlighted|UIControlStateSelected)];
    
    friendOnline = [[UIImageView alloc] initWithFrame:CGRectMake(55,4, 8, 8)];
    [friendOnline setImage:[UIImage imageNamed:@"onlineFlag.png"]];
    [buttonVisit addSubview:friendOnline];
    friendOnline.hidden = YES;
    
    [segmentController setButtonsArray:@[buttonTalk, buttonVisit]];
    
    _badgeViewTalk = [[UIBadgeView alloc] init];
    
    _badgeViewTalk.backgroundColor = [UIColor clearColor];
    _badgeViewTalk.badgeColor = [UIColor redColor];
    [segmentController addSubview:_badgeViewTalk];
    
    //添加显示有新消息的图片
    _redImage = [[UIImageView alloc]initWithFrame:CGRectZero];
    _redImage.image = [UIImage imageNamed:@"unread.png"];
    [segmentController addSubview:_redImage];
    
    [self.navigationItem.titleView.superview bringSubviewToFront:self.navigationItem.titleView];
    self.navigationItem.titleView = segmentController;
    [segmentController setSelectedIndex:1];
    [self setSegmentBadgeValue:[MyAppDataManager getBadgeValue]];
    
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(setUnreadNumber:) name:@"setUnreadNumber" object:nil];
}

//设置值
-(void)setUnreadNumber:(NSNotification *)notifi
{
    NSNumber * UnreadNum = [notifi object];
    [self setSegmentBadgeValue:[UnreadNum integerValue]];
}

//在标题按钮上显示
-(void)setSegmentBadgeValue:(NSInteger)talkValue
{
    NSString * talkStr = [NSString stringWithFormat:@"%d",talkValue];
    float width = [talkStr sizeWithFont:[UIFont boldSystemFontOfSize:14]].width+12;
    
    self.badgeViewTalk.badgeString = talkStr;
    self.badgeViewTalk.frame=CGRectMake(segmentController.frame.size.width/2-width+5, -2, width, 20);
    
    if(talkValue == 0)
    {
        self.badgeViewTalk.hidden = YES;
    }
    else
    {
        self.badgeViewTalk.hidden = NO;
    }
}


#pragma mark -
#pragma mark AKSegmentedControlDelegate

- (void)segmentedViewController:(AKSegmentedControl *)segmentedControl touchedAtIndex:(NSUInteger)index
{
    if(index == 0)
    {
        [self exchangeTalkTableWithVisitRecord];
    }
    selectIndex = index;
}

//切换到对话
-(void)exchangeTalkTableWithVisitRecord
{
    [[NSNotificationCenter defaultCenter]removeObserver:self name:@"setUnreadNumber" object:nil];
    [self.navigationController popViewControllerAnimated:NO];
}

@end
